﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DAO.PO;
using DTO.PO;
using DTO;

namespace BUS
{
    public class Purchase
    {
        public int PoNumber { get; set; }

        public Purchase()
        {
           // PoNumber = GeneratePONumber();
        }

        public void CreatePurchaseOrder(int vendorId, char type, DateTime date, int siteId)
        {
            // insert purchase order
            var order = new OrderDAO();
            var ord = new Order();
            order.Delete(PoNumber);

            ord.POnumber = PoNumber;
            ord.VendorId = vendorId;
            ord.Status = type;
            ord.Date = date;
            ord.SiteId = siteId;
            order.InsertPurchaseOrder(ord);
        }

        public void CreateOrderDetail(int invtId, int qty)
        {
            var ord = new OrderDetail();
            var orderDao = new OrderDetailDAO();


            ord.POnumber = PoNumber;
            ord.InvenId = invtId;
            ord.Quantity = qty;
            var inventoryDao = new InventoryDAO();
            Inventory inventory = inventoryDao.GetInvtPurchaseInfo(invtId);
            int total = qty*inventory.PurcharsePrice;

            ord.Total = total;
            ord.POnumber = PoNumber;
            orderDao.InsertPurchaseOrderDetails(ord);
        }

        public Inventory GetInventoryInfo(int invtID)
        {
            InventoryDAO inventoryDAO = new InventoryDAO();
            return inventoryDAO.GetInvtPurchaseInfo(invtID);
        }
        /*public int GeneratePONumber()
        {
            OrderDAO order = new OrderDAO();
            return order.GetMaxPOnumber() + 1;
        }*/
    }
}
